/* main.vala
 *
 * Copyright 2020 Baloneo
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Simple : Object {

	public string name {get; set;}

	public Simple(string name) {
		this.name = name;
	}

	public async void nap (uint interval, int priority = GLib.Priority.DEFAULT) {
		GLib.Timeout.add (interval, () => {
			nap.callback ();
			return false;
		  }, priority);
		yield;
	  }
	  
	private async void do_stuff () {
		yield nap (1000);
	}
	  

	public signal void foo();

	static int main(string[] args) {
		//  var label = new Gtk.Label("hello world!");
		stdout.printf("hello world!\n");
		var obj = new Simple("张三");
		stdout.printf("%s\n", obj.name);

		obj.foo.connect((s)=> {
			stdout.printf("sssssssssssss\n");
		});

		GLib.MainLoop loop = new GLib.MainLoop ();
		obj.do_stuff.begin ((objj, async_res) => {
			stdout.printf("成功\n");
			obj.foo();
      		loop.quit ();
    	});
  loop.run ();
		

		return 0;
	}
}